package com.cl.mybatis.learn.day06;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
//https://segmentfault.com/a/1190000020974188
public class Mybatis001 {
    public static void main(String[] args) throws IOException {
        

        
        String resource = "day06/mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        
        SqlSession session = sqlSessionFactory.openSession();
        try {
            User test1 = session.selectOne(UserMapper.class.getName() + ".selectById", 0);
            System.out.println("第一次：" + test1);
            User test2 = session.selectOne(UserMapper.class.getName() + ".selectById", 1);
            System.out.println("第二次：" + test2);
        } finally {
            session.close();
        }
    }
}
